package com.rjgc.title.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rjgc.title.mapper.CurrentTitleMapper;
import com.rjgc.title.model.entity.user.CurrentTitle;
import com.rjgc.title.service.CurrentTitleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 现任职称 服务实现类
 * </p>
 *
 * @author 卓抱抱
 * @since 2022-04-25
 */
@Service
public class CurrentTitleServiceImpl extends ServiceImpl<CurrentTitleMapper, CurrentTitle> implements CurrentTitleService {

    @Autowired
    private CurrentTitleMapper currentTitleMapper;


    @Override
    public List<CurrentTitle> getByUserId(String userId) {
        QueryWrapper<CurrentTitle> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userId", userId);

        List<CurrentTitle> currentTitles = currentTitleMapper.selectList(queryWrapper);
        return currentTitles;
    }

    @Override
    public CurrentTitle getCurrentTitle(String userId) {
        QueryWrapper<CurrentTitle> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userId", userId);
        queryWrapper.eq("flag", 1);

        CurrentTitle currentTitle = currentTitleMapper.selectOne(queryWrapper);
        return currentTitle;
    }

    @Override
    public void saveCurrentTitle(CurrentTitle currentTitle) {
        if (currentTitle.getId() != null) {
            // 更新
            currentTitleMapper.updateById(currentTitle);
        } else {
            currentTitleMapper.insert(currentTitle);
        }
    }
}


